import {
	LoginCenterApi
} from "./modules/LoginCenterApi"


let baseUrl = ''
let currentDomain = ''
// #ifdef H5
currentDomain = window.location.host
// #endif

const getToken = () => {
	let page = getCurrentPages().pop();
	console.log(page, "page");
	return new Promise((resolve, reject) => {
		// #ifdef MP-WEIXIN
		uni.login({
			provider: 'weixin',
			success: (res1) => {
				LoginCenterApi.login({
					jsCode: res1.code,
					byOpneId: page.options.byOpneId || ''
				}).then((res) => {
					uni.setStorageSync('token', res.data);

					page.onShow();
					resolve(res.data); // 临时路径
				});
			}
		});
		// #endif
		// #ifdef H5
		console.log(currentDomain, 'currentDomain')
		window.location.href = 'https://www.yirenyian.com/user/login?target=' + encodeURIComponent(
			'http://' + currentDomain + '/index.html')
		resolve(currentDomain)

		// #endif
	})
}
// #ifdef MP-WEIXIN
const accountInfo = uni.getAccountInfoSync()
var envVersion = accountInfo.miniProgram.envVersion;
switch (envVersion) {
	case 'develop': //体验版 and 开发版
		baseUrl = 'https://java.vrupup.com/j1500/api/'
		console.log(`\n %c 体验版 and 开发版 \n\n`,
			'color: #ffffff; background: #e82702; padding:5px 0; border-radius: 5px;');
		break;
	case 'trial': //体验版 and 开发版
		baseUrl = 'https://java.vrupup.com/j1500/api/'
		console.log(`\n %c 体验版 and 开发版 \n\n`,
			'color: #ffffff; background: #e82702; padding:5px 0; border-radius: 5px;');
		break;
	case 'release': //正式版
		baseUrl = 'https://java.vrupup.com/j1500/api/' // 基础版测试
		console.log(`\n %c 正式版 \n\n`, 'color: #ffffff; background: #15d36a; padding:5px 0; border-radius: 5px;');
		break;
	default:
		console.error('判断出错了', envVersion)
		break;
}
// #endif
// #ifdef H5
if (process.env.NODE_ENV === 'development') {
	console.log('开发环境')
	baseUrl = 'https://java.vrupup.com/medical-care/api/'
	console.log(`\n %c 开发环境 \n\n`, 'color: #ffffff; background: #e82702; padding:5px 0; border-radius: 5px;');
} else {
	console.log('生产环境')
	baseUrl = 'https://java.vrupup.com/medical-care/api/'
	console.log(`\n %c 生产环境 \n\n`, 'color: #ffffff; background: #15d36a; padding:5px 0; border-radius: 5px;');
}
// #endif


export {
	baseUrl,
	getToken,
	// #ifdef H5
	currentDomain,
	// #endif
}